package com.lovetemperature.action;

import java.util.List;

import com.lovetemperature.model.GoodCategory;
import com.lovetemperature.model.GoodSet;
import com.lovetemperature.model.Stock;
import com.lovetemperature.service.GoodService;
import com.lovetemperature.service.StockService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowGoodsAction extends ActionSupport {
	private StockService stockService;
	private List<Stock> stockList;
	private String category;
	private String showCategory;
	
	public String defaultShow(){	//默认显示蛋糕
		stockList = stockService.findByCategory(GoodCategory.蛋糕);
		showCategory = "蛋糕";
		return "success";
	}

	@Override
	public String execute() throws Exception {
		if (category == null) { // 返回首页
			showCategory = "首页";
		} else if (category.equalsIgnoreCase(GoodCategory.蛋糕.toString())) {
			stockList = stockService.findByCategory(GoodCategory.蛋糕);
			showCategory = "蛋糕";
		} else if (category.equalsIgnoreCase(GoodCategory.面包.toString())) {
			stockList = stockService.findByCategory(GoodCategory.面包);
			showCategory = "面包";
		} else if (category.equalsIgnoreCase(GoodCategory.干点.toString())) {
			stockList = stockService.findByCategory(GoodCategory.干点);
			showCategory = "干点";
		} else if (category.equalsIgnoreCase(GoodCategory.拌手礼.toString())) {
			stockList = stockService.findByCategory(GoodCategory.拌手礼);
			showCategory = "拌手礼";
		} else if (category.equalsIgnoreCase(GoodCategory.饮品.toString())) {
			stockList = stockService.findByCategory(GoodCategory.饮品);
			showCategory = "饮品";
		} else if (category.equalsIgnoreCase(GoodCategory.其他.toString())) {
			stockList = stockService.findByCategory(GoodCategory.其他);
			showCategory = "其他";
		} else { // 返回首页
			showCategory = "首页";
		}
		category = null;
		ActionContext.getContext().put("showCategory", showCategory);
		return super.execute();
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getShowCategory() {
		return showCategory;
	}

	public void setShowCategory(String showCategory) {
		this.showCategory = showCategory;
	}

	public StockService getStockService() {
		return stockService;
	}

	public void setStockService(StockService stockService) {
		this.stockService = stockService;
	}

	public List<Stock> getStockList() {
		return stockList;
	}

	public void setStockList(List<Stock> stockList) {
		this.stockList = stockList;
	}
}
